package com.wica.view.tab_preference;

import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.wica.facetube.R;

public class TabPreferencesSuggestions extends TabPreferences{

	// *************** Constants ************** //  
    public static final String SETTINGS_1= "suggestions_numberOfResults";
    public static final String SETTINGS_2= "mood";
    public static final int MAX_SETTINGS_1=30;
	public static final String LOG_TAG = "__FT.TabPreferencesSuggestions__";

	// *************** Methods **************************** //
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        
        // Load the preferences from an XML resource
        addPreferencesFromResource(R.xml.suggestions_preferences);    
    }// onCreate method
    
	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		Log.v(LOG_TAG,LOG_TAG+"cambio el mood? "+key);
		if (key.equals(SETTINGS_1)) {
        	Integer integer = new Integer(sharedPreferences.getString(key, "0"));
        	int i = integer.intValue();
        	if (i<MAX_SETTINGS_1){
        		Toast.makeText(this, sharedPreferences.getString(key, "0")+" results will be shown.", Toast.LENGTH_SHORT).show();
        		finish();
        	}else if (i==MAX_SETTINGS_1){
        		Toast.makeText(this, "The maximum number of results ("+MAX_SETTINGS_1+") will be shown.", Toast.LENGTH_SHORT).show();
        		finish();
        	}else{
        		Editor s = sharedPreferences.edit();        		
        		s.putString(key, ""+MAX_SETTINGS_1);        		
        		s.commit();
        	}            
        }		
	}// onSharedPreferenceChanged method
	
}// TabPreferencesSuggestions class